//
// Created by chaseaishang on 23-5-10.
//

#include "ResourceManager.h"
ResourceManager* ResourceManager::instance= nullptr;
ResourceManager* ResourceManager::get_instance() {
    if(instance)
    {
        return ResourceManager::instance;
    }
    else
    {
        instance=new ResourceManager();
        return instance;

    }

}

ResourceManager::ResourceManager()
{

}

ResourceManager::~ResourceManager() {






}



std::shared_ptr<Shader> ResourceManager::LoadShader( std::string VS_file_name,  std::string FS_file_name, std::string shader_name)
{

    Shaders[shader_name]= std::make_shared<Shader>(VS_file_name,FS_file_name);
    return Shaders[shader_name];
}

std::shared_ptr<Shader> ResourceManager::GetShader(std::string shader_name)
{
    auto iter=Shaders.find(shader_name);
    ASSERT(iter!=Shaders.end());

    return iter->second;
}

std::shared_ptr<Texture> ResourceManager::LoadTexture(std::string texture_file_name, std::string texture_name) {
    Textures[texture_name]=std::make_shared<Texture>(texture_file_name);

    return  Textures[texture_name];
}

std::shared_ptr<Texture> ResourceManager::GetTexture(std::string texture_name) {
    auto iter=Textures.find(texture_name);
    ASSERT(iter!=Textures.end());

    return iter->second;
}

void ResourceManager::init()
{

}

void ResourceManager::Delete()
{
    if(instance)
    {
        delete ResourceManager::instance;
        instance= nullptr;
    }

}
